package com.example.day2.live;

import androidx.lifecycle.MutableLiveData;

import com.example.day2.entity.GiftResult;
import com.example.day2.entity.NormalResult;
import com.example.day2.mvvm.base.BaseRepo;
import com.example.day2.mvvm.base.GuanZhuParam;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class LiveRepo extends BaseRepo {
    public void getGuanzhu(GuanZhuParam guanZhuParam, MutableLiveData<NormalResult> success,MutableLiveData<String> fail){
        apiService.getNormal(guanZhuParam)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NormalResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NormalResult normalResult) {
                        success.setValue(normalResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void getNoGuanzhu(GuanZhuParam guanZhuParam, MutableLiveData<NormalResult> success, MutableLiveData<String> fail){
        apiService.getNoGuanzhu(guanZhuParam)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NormalResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NormalResult normalResult) {
                        success.setValue(normalResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void getGift(MutableLiveData<GiftResult> success, MutableLiveData<String> fail){
        apiService.getGift()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<GiftResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(GiftResult giftResult) {
                        success.setValue(giftResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
